package com.anolesoft.twelveFactory.planManagement.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.sql.Date;
import java.util.List;
import java.util.stream.Collectors;
//工艺计划 实体类
@Data
@TableName("twelve_factory_plan_process")
public class Process implements  Comparable<Process>{
    @TableId(value = "objuid")
    private String objuid;
    private  String th;
    private String fth;
    private  String jx;
    private  String ljmc;
    private String dz;
    private  String dj;
    private  String nbfg;
    private String czqlj;
    private  String gylx;
    private  String xkh;
    private String cdh;
    private  String jmjlb;
    private  String ljlx;
    private  String jflx;
    private  String cpz;
    private String xgyy;
    private  String jjx;
    private  String clph;
    private String clphzt;
    private  String clgg;
    private String c;
    private  String k;
    private  String g;
    private  String dzjdh;
    private String ljtx;
    private  String rcllx;
    private  String bfcl;
    private String pq;
    private  String qx;
    private  String tzjc;
    private String cs;
    private  String xcyl;
    private  String dhxpg;
    private String qtzjgx;
    private  String zl;
    private  String bz;
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date cjsj;
    private  String cjr;
    private Integer pageNo; //页数
    private Integer pageSize; //每页显示条数
    private Integer xgzt;
    private String jhzt;// 计划状态
    private String wyzd;
    private List<Process> children; //序号
    private String code;
    private String pt;
    private String ld;
    private  String xl;
    private  String wg;
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date gskhrq;
    private String fz;
    private String swgx;
    private String jfsx;
    private String jfcj;
    private String jscj;
    private String jd;
    private String djs;
    private Integer mlkczs;
    @Override // 字符串比较
    public int compareTo(Process o) {
        return o.getTh().compareTo(this.th);
    }
    //构造函数
    public Process(String th, String fth,String jx) {
        super();
        this.th = th;
        this.fth = fth;
        this.jx = jx;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) //1.判断this与obj是否引用同一个对象
            return true;
        if (obj == null) //2.判断obj是否为null
            return false;
        if (getClass() != obj.getClass()) //3.判断this与obj是否属于同一类
            return false;
        Process other = (Process) obj; //4.将obj转换为相应的类类型

        //5.判断域（域）是否相同，基本数据类型使用==，对象域使用equals方法比较
        if (th == null) {
            if (other.th != null)
                return false;
        } else if (!th.equals(other.th))
            return false;
        return true;
    }


    //hashCode() 方法用于返回字符串的哈希码。
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((th == null) ? 0 : th.hashCode());
        return result;
    }

    public  static void setChildren(List<Process> all, Process plan){
        String th = plan.getTh();
        List<Process> children = all.stream().filter(p -> {
            return p.getFth()!=null && th.equals(p.getFth());
        }).collect(Collectors.toList());
        if (children.size() > 0) {
            children.stream().forEach(c -> {
                Process.setChildren(all, c);
            });
            plan.setChildren(children);
        }
    }

    public  static void getCondition(List<Process> all,Process plan){
        String th = plan.getTh();
        List<Process> children = all.stream().filter(p -> {
            return p.getFth()!=null && th.equals(p.getFth());
        }).collect(Collectors.toList());
        if (children.size() > 0) {
            children.stream().forEach(c -> {
                Process.setChildren(all, c);
            });
            plan.setChildren(children);
        }
    }

    public Process() {
        super();
    }

    public static void setChildrenCode(List<Process> list, String pCode) {
        for (int i = 0; i < list.size(); i++) {
            String code = pCode + "."+(i+1);
            list.get(i).setCode(code);
            List<Process> children = list.get(i).getChildren();
            if(children != null && !children.isEmpty()) {
                Process.setChildrenCode(children, code);
            }
        }
    }

}
